<?php
class user_model extends CI_Model 
{
    protected $user_tab = 'users';

    public  function __construct() {
		parent::__construct();
        $this->load->database();
    }
    
    public function user_add($username, $email, $userpwd)
    {
        $data[0]=$username;
        $data[1]=$email;
        $data[2]=$userpwd;
        $sql = "insert into ao_users(user_login, user_email, user_pass) values(?, ?, md5(?))";
        
        $bool = $this->db->query($sql, $data);
        
        return $bool;
    
    }
    
    public function login_check($userinfo, $userpwd)
    {
        
        $this->db->where('user_login', $userinfo);
        $this->db->where('user_pass', md5($userpwd));
        $this->db->or_where('user_email', $userinfo);
        $result = $this->db->get($this->user_tab)->row_array();
        if($result){
            $_SESSION['userid'] = $result['ID'];
            $_SESSION['username'] = $result['user_login'];
            $_SESSION['useremail'] = $result['user_email'];
            $_SESSION['loginip'] = $_SERVER['REMOTE_ADDR'];
            return $result;
        }
        return $result;
       
    }
    
    public function register_ajax($val)
    {
        $this->db->where('user_login', $val);
        $this->db->or_where('user_email', $val);
        $this->db->or_where('user_pass', md5($val));
        $result = $this->db->get($this->user_tab)->row_array();
        return $result;
        

    }
}